/*
 * @Author: Wxx
 * @Date: 2022-03-01 16:54:42
 * @LastEditors: Wxx
 * @LastEditTime: 2022-03-01 16:57:34
 * @Description:
 */
import React, { Component, forwardRef } from "react";

export default class App extends Component {
  myRef = React.createRef();
  render() {
    return (
      <div>
        <button
          onClick={() => {
            this.myRef.current.focus();
            this.myRef.current.value = "";
          }}
        >
          点我获取焦点 清空数据
        </button>
        <Child ref={this.myRef} />
      </div>
    );
  }
}

const Child = forwardRef((props, ref) => (
  <div>
    <input ref={ref} defaultValue="kkk" />
  </div>
));
